<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.2</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" href="./css/font.css">
    <link rel="stylesheet" href="./css/xadmin.css">
    <script src="./lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="./js/xadmin.js"></script>
    <script src="./js/global.js"></script>
    <script src="./js/config.js"></script>
</head>
<body>
<div class="x-nav">
            <span class="layui-breadcrumb">
                <a href="">首页</a>
                <a href="">系统基础</a>
                <a>
                    <cite>配置管理</cite></a>
            </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
    </a>
</div>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <form class="layui-form layui-col-space5">

                    </form>
                </div>

                <div class="layui-card-header">

                </div>
                <div class="layui-card-body ">
                    <table class="layui-table layui-form">
                        <thead>
                        <tr>
                            <th>标识</th>
                            <th>标题</th>
                            <th>类型</th>
                            <th>排序</th>
                            <th>状态</th>
                            <th>操作</th></tr>
                        </thead>
                        <tbody class="configlist">
                        </tbody>
                    </table>
                </div>

            </div>
        </div>
    </div>
</div>
</body>
<script>
    layui.use(['laydate', 'form','request','laypage'],
    function() {
        var laydate = layui.laydate;
        $ = layui.jquery;
        var form = layui.form,
            layer = layui.layer;
        var request = layui.request;
        var laypage = layui.laypage;
        var adminToken = localStorage.getItem("adminToken");
        //获得get参数
        var $_GET = (function(){
            var url = window.document.location.href.toString();
            var u = url.split("?");
            if(typeof(u[1]) == "string"){
                u = u[1].split("&");
                var get = {};
                for(var i in u){
                    var j = u[i].split("=");
                    get[j[0]] = j[1];
                }
                return get;
            } else {
                return {};
            }
        })();

        //获取获取分组的配置
        request.ajax(requestUri+'/admin/system/config/getconfigcount', 'get', 'json', {
            'token': adminToken,
            'group': $_GET['group']
        }, function (req) {
            if(req.code == 1000){
                var num = req.data.num;
            }
            //执行一个laypage实例
            laypage.render({
                elem: 'page',
                count: num, //数据总数，从服务端得到
                curr:1,
                jump: function(obj, first){
                    //obj包含了当前分页的所有参数，比如：
//                    console.log(obj.curr); //得到当前页，以便向服务端请求对应页的数据。
//                    console.log(obj.limit); //得到每页显示的条数
                        request.ajax(requestUri+'/admin/system/config/getlist', 'get', 'json', {
                            'token': adminToken,
                            'curr':obj.curr,
                            'limit':obj.limit,
                            'group': $_GET['group']
                        }, function (req) {
                            var str = '';
                            $.each(req.data,function(i,item){
                                str+='<tr>';
                                str+='<td>'+item.name+'</td>'
                                str+='<td>'+item.title+'</td>';
                                str+='<td>'+item.type+'</td>';
                                str+='<td>'+item.sort+'</td>';
                                if(item.status == 1){
                                    str+='<td>'+'开启'+'</td>';
                                }else {
                                    str+='<td>'+'关闭'+'</td>';
                                }
                                str+='<td class=\"td-manage\">';
                                if(item.system != 1){
                                    str+='<a title=\"查看\" onclick=\"xadmin.open(\'编辑\',\'config-edit.html?id='+item.id+'\')\" href=\"javascript:;\">';
                                }else {
                                    str+='<a style=\"pointer-events: none;color: red;\" title=\"查看\" onclick=\"xadmin.open(\'编辑\',\'config-edit.html?id='+item.id+'\')\" href=\"javascript:;\">';
                                }
                                str+='<i class=\"layui-icon\">&#xe63c;</i></a>';
                                if(item.system != 1){
                                    str+='<a title=\"删除\" onclick=\"member_del(this,\''+item.id+'\')\" href=\"javascript:;\">';
                                }else {
                                    str+='<a style="pointer-events: none;color: red;" title=\"删除\" onclick=\"member_del(this,\''+item.id+'\')\" href=\"javascript:;\">';
                                }
                                str+='<i class=\"layui-icon\">&#xe640;</i></a>';
                                str+='</td></tr>';
                            });
                            $('.configlist').html(str);
                        },function (req) {
                        });
                }
            });
        });

        //获取分组title
        request.ajax(requestUri+'/admin/system/config/getconfigtitle', 'get', 'json', {
            'token': adminToken
        }, function (req) {
            if(req.code == 1000){
                var str = '';
                $.each(req.data,function(i,item){
                    str +='<button class=\"layui-btn layui-btn-sm\" id=\"'+item+'\" onclick=\"configHref(this.id)\"> '+i+' </button>';
                });
                str +='<button class=\"layui-btn\" onclick=\"xadmin.open(\'添加分组\',\'config-group-add.html\',800,600)\">';
                str +=' <i class=\"layui-icon\"></i>添加分组</button></div>';
                str +='<button class=\"layui-btn\" onclick=\"xadmin.open(\'添加配置\',\'config-add.html\',800,600)\">';
                str +=' <i class=\"layui-icon\"></i>添加配置</button></div>';
                $('.layui-card-header').html(str);
            }
        });
    });

    //跳转配置list页面
    function configHref (e) {
        window.location.href=requesturi+'/admin/config-list.html?group='+e;
    }

/*用户-删除*/
function member_del(obj, id) {
    layer.confirm('确认要删除吗？',
        function(index) {
            //发异步删除数据
            layui.use([ 'form','request'],
                function() {
                    var form = layui.form,
                        layer = layui.layer;
                    var request = layui.request;
                    var adminToken = localStorage.getItem("adminToken");
                    //发异步删除数据
                    request.ajax(requestUri+'/admin/system/config/deleteconfig', 'get', 'json', {
                        'token': adminToken,
                        'id': id
                    }, function (req) {
                        $(obj).parents("tr").remove();
                        layer.msg('已删除!', {
                            icon: 1,
                            time: 1000
                        });
                    }, function (req) {
                        console.log(req);
                        layer.msg('删除失败');
                    });
                });
        });
}
</script>

</html>